//
//  ShopWebViewController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/8/8.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "ShopWebViewController.h"
#import <WebKit/WebKit.h>

@interface ShopWebViewController ()<WKNavigationDelegate>
{
      MBProgressHUD *_progressHUD;
}

@end


@implementation ShopWebViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupWebView];
}

- (void)setupWebView
{
    WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH,HEIGHT*1.5)];
    
    
    
    NSString *temp = [NSString stringWithFormat:@"<head><style>img{max-width:%lfpx !important;}</style></head>%@",WIDTH, self.htmlStr];
//    NSLog(@"%@",self.htmlStr);
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:temp]]];
    [self.view addSubview:webView];
    
    webView.navigationDelegate = self;
}

// 页面开始加载时调用
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
{
    //菊花加载
    _progressHUD = [MBProgressHUD loadingInformationToView];
    [self.view addSubview:_progressHUD];
}
// 当内容开始返回时调用
//- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation;
// 页面加载完成之后调用
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    [_progressHUD hide:YES];
}
// 页面加载失败时调用
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation
{
    NSLog(@"%@",navigation)
}
@end
